#include "GPIO.h"
/*
    PB4->LED3(O)
    PC6->LED2(O) PC7->LED1(O) PC14->DR(O) PC15->KEY(I)
    PD0->RES1(O) PD1->DC1(O)  PD2->BLK(O) PD3->TP1(O)
    PA8->TIM1_CH1(AF)   PA9->TIM1_CH2(AF)   PA10->TIM1_CH3(AF)
    PA13->TIM1_CH1N(AF) PA14->TIM1_CH2N(AF) PA15->TIM1_CH3N(AF)
    PC13->TIM1_BK(AF)
*/
void GPIO_Init(void)
{
    #if RCU_MCO_MODE==1
    /*
    1.开启GPIOA时钟
    2.设置PA8为AF模式
    3.设置为推挽输出模式
    4.配置复用号
    */
    RCC->IOPENR |= 0x00000001;
    GPIOA->MODER &= 0xFFFCFFFF;
    GPIOA->MODER |= 0x00020000;
    GPIOA->OTYPER &=~ (uint32_t)(1<<8);
    GPIOA->OSPEEDR &= 0xFFFCFFFF;
    GPIOA->OSPEEDR |= 0x00030000;
    GPIOA->AFR[1] &= 0xFFFFFFF0;
    #endif
    RCC->IOPENR |= 0x0000000f;

    GPIOB->MODER &= 0xfffffcff;//MODE4[1:0] = 0b00
    GPIOB->MODER |= 0x00000100;//MODE4[1:0] = 0b01
    GPIOB->OSPEEDR |= 0x00000200;
    GPIOB->ODR &=~ (uint32_t)(1<<4);

    GPIOC->MODER &= 0x0fff0fff;//MODE6[1:0] = 0b00   MODE7[1:0] = 0b00
                               //MODE14[1:0] = 0b00  MODE15[1:0] = 0b00
    GPIOC->MODER |= 0x10005000;//MODE6[1:0] = 0b01   MODE7[1:0] = 0b01
                               //MODE14[1:0] = 0b01  MODE15[1:0] = 0b01
    GPIOC->OSPEEDR |= 0x2000a000;                           
    GPIOC->ODR &=~ (uint32_t)((1<<6)+(1<<7)+(1<<14)+(1<<15));    


    GPIOD->MODER &= 0xffffff00;//MODE0[1:0] = 0b00   MODE1[1:0] = 0b00
                               //MODE2[1:0] = 0b00  MODE3[1:0] = 0b00
    GPIOD->MODER |= 0x00000055;//MODE0[1:0] = 0b01   MODE1[1:0] = 0b01
                               //MODE2[1:0] = 0b01  MODE3[1:0] = 0b01
    GPIOD->OSPEEDR |= 0x000000aa;
    GPIOD->ODR &=~ (uint32_t)((1<<0)+(1<<1)+(1<<2)+(1<<3));
    
    /*    
        PA8->TIM1_CH1(AF)   PA9->TIM1_CH2(AF)   PA10->TIM1_CH3(AF)
        PA13->TIM1_CH1N(AF) PA14->TIM1_CH2N(AF) PA15->TIM1_CH3N(AF)
        PC13->TIM1_BK(AF)
    */
    GPIOA->MODER &= 0xffc0ffff;
    GPIOA->MODER |= 0x002a0000;
    GPIOA->OSPEEDR |= 0x002a0000;
    GPIOA->AFR[1] |= 0x00000222;
    
    GPIOB->MODER &= 0x03ffffff;
    GPIOB->MODER |= 0xa8000000;
    GPIOB->OSPEEDR |= 0xa8000000;
    GPIOB->AFR[1] |= 0x22200000;

    GPIOC->MODER &= 0xf3ffffff;
    GPIOC->MODER |= 0x08000000;
    GPIOC->AFR[1] |= 0x00200000;
}

